﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;

namespace broker.duty.JHRS
{
    class Class3
    {
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            int ffee = 0;
            int basicfee = 0;
            int extrafee = 0;
            int addfee = 0;

            double deduct = 0;

            int overPeriod = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("约定缴费期(年)"));

            if (ppa.Period < overPeriod)
            {
                ffee = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("期交保险费"));

                basicfee = ffee > 6000 ? 6000 : ffee;
                extrafee = ffee - basicfee;

                if (ppa.Period == 0)
                {
                    deduct = basicfee * 0.5;
                    deduct += extrafee * 0.05;
                }
                else if (ppa.Period == 1)
                {
                    deduct = basicfee * 0.25;
                    deduct += extrafee * 0.05;
                }
                else if (ppa.Period == 2)
                {
                    deduct = basicfee * 0.15;
                    deduct += extrafee * 0.05;
                }
                else if (ppa.Period == 3 || ppa.Period == 5)
                {
                    deduct = basicfee * 0.1;
                    deduct += extrafee * 0.05;
                }
                else if (ppa.Period >= 4 && ppa.Period <= 9)
                {
                    deduct = basicfee * 0.05;
                    deduct += extrafee * 0.05;
                }
                else
                {
                    deduct = basicfee * 0.025;
                    deduct += extrafee * 0.025;
                }
            }

            if (ppa.SchemePeriodActing.InsurantStates.Contains("追加费用"))
            {
                addfee = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("追加费用"));
                if (addfee <= 50000)
                    deduct += addfee * 0.05;
                else if (addfee <= 500000)
                    deduct += addfee * 0.025;
                else if (addfee <= 5000000)
                    deduct += addfee * 0.015;
                else
                    deduct += addfee * 0.005;
            }

            if (ppa.Period < ppa.PolicyActing.Policy.Fees.Count())
            {
                if (ppa.Period > 0 && ppa.PolicyActing.Policy.Fees[ppa.Period] <= double.Epsilon)
                {
                    ppa.PolicyActing.Policy.Fees[ppa.Period] = ppa.PolicyActing.Policy.Fees[ppa.Period - 1];
                }


                double d = ppa.PolicyActing.Policy.Fees[ppa.Period];
                deduct += d;//约定风险金对应的保费

            }

            da.Value = ffee + addfee - deduct;

            if (ppa.Period > 0)
            {
                double f = (double)ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("分红率(预估)");
                IPolicyPeriodActing pppa = ppa.PolicyActing.PeriodActings[ppa.Period - 1];
                da.Value += pppa.GetDutyTotalValue("个人账户") * f;
            }

           

            ppa.Fee = ffee + addfee;

            if (ppa.GetDutyTotalValue("个人账户") <= 0)
            {
                ppa.IsCurrentFinish = true;
                da.Description = "个人账户余额不足，合同终止!";
            }
        }
    }
}
